﻿using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using T4UtilityBelt.DataDesigns;
using T4UtilityBelt.Serializers;
using T4UtilityBelt.UxDesigns.Bindings;
using T4UtilityBelt.UxDesigns.Controls;
using T4UtilityBelt.UxDesigns.Screens2.Renders;

namespace T4UtilityBelt.UxDesigns.Screens2
{
    //[XDefaultProperty("Content")]
    public class ContentEntityScreen<TView, TRenderer> : EntityScreen<TView, TRenderer>
        where TView : View<TView, TRenderer>
        where TRenderer : class, T4UtilityBelt.UxDesigns.Screens.Renders.IViewRenderer<TView, TRenderer>
    {
        private StackPanelControl _content;

        public ContentEntityScreen()
        {
            StandardConstructor();
        }

        public ContentEntityScreen(string entityName) : base(entityName)
        {
            StandardConstructor();
        }

        public ContentEntityScreen(string entityName, string screenName)
            : base(entityName, screenName)
        {
            StandardConstructor();
        }

        private void StandardConstructor()
        {
            Content = new StackPanelControl();
        }

        internal override void FixModel(T4UtilityBelt.DataDesigns.EntityModel model)
        {
            base.FixModel(model);

            Entity = model.GetEntity(EntityName);
            if (Entity != null)
            {
                Content.FixModel(Entity);
            }
        }

        public StackPanelControl Content
        {
            get { return _content; }
            set
            {
                Controls.Switch(_content, value);
                _content = value;
            }
        }
    }
}